package com.zz.dto;

import cn.hutool.crypto.SecureUtil;
import com.zz.domain.User;
import org.springframework.http.HttpRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
/**
 * 自动登录的 存在全局上下文application的数据传输对象
 * */
public class LoginToken {
    private String ip;
    private String userAgent;
    private User user;
    private String now;

    private String token;
  /**
   * 生成自动登录的凭证
   * */
    public  String generateToken(){
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.append(ip);
        strBuilder.append(userAgent);
        strBuilder.append(user.getEmail());
        strBuilder.append(now);
        //增加md5的复杂度,起混淆视听的作用,让破解的人更难猜
        strBuilder.append("1254675432");
        String token =  SecureUtil.md5(strBuilder.toString());
        return  token;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setNow(String now) {
        this.now = now;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getIp() {
        return ip;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public User getUser() {
        return user;
    }

    public String getNow() {
        return now;
    }

    public String getToken() {
        return token;
    }
}
